package com.company.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Created by ruoan on 2020/9/25 15:05
 *  另一个代理类
 */
@Component
@Aspect
@Order(1)
public class AnotherUserProxy2 {


    @Pointcut(value="execution(* com.company.aspectj.AnotherUser.saySomething(..))")
    public void publicPointCut(){
    }

    // 对AnotherUser类的saySomething方法进行前置通知
    @Before(value = "publicPointCut()")
    public void before(){
        System.out.println("AnotherUserProxy2--->before");

    }
    //对AnotherUser类的saySomething方法进行最终通知
    @After(value="publicPointCut()")
    public void after(){
        System.out.println("AnotherUserProxy2--->after");
    }
    //对AnotherUser的saySomething方法进行后置异常通知
    @AfterThrowing(value = "publicPointCut()")
    public void afterThrowing(){
        System.out.println("AnotherUserProxy2--->afterThrowing");
    }

    //对AnotherUser的saySomething方法进行后置通知
    @AfterReturning(value = "publicPointCut()")
    public void afterReturning(){
        System.out.println("AnotherUserProxy2--->afterReturning");
    }

    //对AnotherUser的saySomething方法进行环绕通知
    @Around(value = "publicPointCut()")
    public void around(ProceedingJoinPoint joinPoint){
        System.out.println("AnotherUserProxy2--->around前");
        try {
            joinPoint.proceed(); //执行被代理的方法
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("AnotherUserProxy2--->around后");


    }

}
